import { getLevelFirst, getLevelZero, getUserID } from '@/utils';

const ProcurementMethodManageTabSwitch = (curRes: Record<string, any>) => {
  const ApplyManageTab = () => {
    if (curRes?.['/purchaseApplyController/createCompanyID']) {
      return {
        createCompanyID: getLevelZero(),
        params: 'createCompanyID',
        key: 'ApplyManageTabKey',
      };
    } else if (curRes?.['/purchaseApplyController/createDepartmentID']) {
      return {
        createDepartmentID: getLevelFirst(),
        params: 'createDepartmentID',
        key: 'ApplyManageTabKey',
      };
    } else if (curRes?.['/purchaseApplyController/createrID']) {
      return {
        createrID: getUserID(),
        params: 'createrID',
        key: 'ApplyManageTabKey',
      };
    }
  };

  const ApplyCheckTab = () => {
    if (curRes?.['/needController/getMyCheck']) {
      return {
        createDepartmentID: getLevelFirst(),
        params: 'createDepartmentID',
        key: 'NeedCheckTabKey',
        state: 2,
      };
    }
  };

  return [
    {
      title: '变更管理',
      key: 'ApplyManageTabKey',
      visible:
        (curRes?.['/purchaseApplyController/createCompanyID'] ||
          curRes?.['/purchaseApplyController/createDepartmentID'] ||
          curRes?.['/purchaseApplyController/createrID']) ??
        false,
      md: 2,
      sm: 24,
      params: ApplyManageTab(),
    },
    {
      title: '我的审核',
      key: 'ApplyCheckTabKey',
      visible: curRes?.['/purchaseApplyController/myApplyCheck'] ?? false,
      md: 2,
      sm: 24,
      params: ApplyCheckTab(),
    },
  ];
};

const MethodsChangeTab = (curRes) => {
  if (curRes?.['/purchaseSourceChangeController/applyCompanyID']) {
    return {
      applyCompanyID: getLevelZero(),
      params: 'applyCompanyID',
    };
  } else if (curRes?.['/purchaseSourceChangeController/applyDepartmentID']) {
    return {
      applyDepartmentID: getLevelFirst(),
      params: 'applyDepartmentID',
      key: 'ApplyManageTabKey',
    };
  } else if (curRes?.['/purchaseSourceChangeController/applyerID']) {
    return {
      applyerID: getUserID(),
      params: 'applyerID',
      key: 'ApplyManageTabKey',
    };
  }
};

export { ProcurementMethodManageTabSwitch, MethodsChangeTab };
